<%@ page language="java" import="b.News,b.User,d.DBUtils,org.apache.commons.lang3.StringEscapeUtils" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<meta http-equiv="Content-Script-Type" content="text/javascript" />
		<meta http-equiv="Content-Style-Type" content="text/css" />
		<title>News</title>

		<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/main.css" />
		<style type="text/css" media="all">
			.m_1line {
				width:640px;
				height:22px;
				line-height:22px;
				border:1px solid rgb(204, 204, 204);
				margin-top:2px;
			}

			#m_content {
				width:640px;
				height:100px;
			}

			.m_meta {
				font-size:12px;
				color:grey;
				margin:4px 0 4px 4px;
			}

			.m_meta .fld {
				font-style:italic;
				margin-right:6px;
			}

			.m_meta .val {
				margin-right:8px;
			}

		</style>
	</head>
	<body>

	<div class="m_edit">
		<input type="text" name="title" id="m_title" class="m_1line"/>
		<div class="m_meta">
			<span class="fld">文档创建时间</span><span class="val" id="m_createdTime">2011年12月31日</span>
		</div>
		<textarea id="m_content" style="display:none;"></textarea>
		<input type="text" name="source" id="m_source" class="m_1line"/>
		<ul class="m_buttonbar" style="margin-top:4px;">
			<li class="m_bb_0" onclick="javascript:saveData()">保存</li>
			<li>归档</li>
			<li class="m_bb_n">删除</li>
		</ul>
	</div>
	<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.6.2.min.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath()%>/js/nicEdit.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath()%>/js/utils.js"></script>
	<script type="text/javascript">
		<%
			News current = (News)request.getAttribute("Entity");
		%>
		var data={
			title:"<%=StringEscapeUtils.escapeEcmaScript(current.getTitle())%>",
			content:"<%=StringEscapeUtils.escapeEcmaScript(current.getContent())%>",
			createTime:"<%=DBUtils.datetimeFormat.format(current.getCreatedOn())%>",
			source:"<%=StringEscapeUtils.escapeEcmaScript(current.getSource())%>"
		};

		var myNicEditor;
		bkLib.onDomLoaded(function() {
			myNicEditor = new nicEditor({
				maxHeight:320,
				iconsPath:"<%=request.getContextPath()%>/img/nicEditorIcons.gif"});
			myNicEditor.panelInstance("m_content");
			loadData();
		});

		function loadData(){
			$("#m_title").attr("value",data.title);
			$("#m_source").attr("value",data.source);
			$("#m_createdTime").text(Date.parsef(data.createTime).format("yyyy年MM月dd日 hh:mm:ss"));
			nicEditors.findEditor("m_content").setContent(data.content);
		}
		
		function saveData(){
			$.ajax(window.location.href,{
				type:'POST',
				contentType:'application/x-www-form-urlencoded',
				data:{
					title:document.getElementById("m_title").value,
					source:document.getElementById("m_source").value,
					content:nicEditors.findEditor("m_content").getContent()
				},
				success:function(data, textStatus, jqXHR){
					var retval;
					eval("retval="+data);
					if(retval._==0) {
						window.location.href = window.location.href.replace(/(.+\/maint\/news\/)(\d+|create)$/,"$1"+retval.UID); 
					}
				}
			});
		}
	</script>
	</body>
</html>